//
//  inheritance_special.hpp
//  learnC++
//
//  Created by liuzhibing on 2018/6/12.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef inheritance_special_hpp
#define inheritance_special_hpp

#include <stdio.h>
#include <iostream>

//一般想向某个类添加新功能时使用继承，也可用于第三方

class Base3
{
public:
    int m_public;
    
    int getPublic(){
        std::cout << "Base3的";
        return m_public;
    }
    
private:
    int m_private;
protected:
    int m_protected;
};

class Pri: private Base3 // note: private inheritance
{
    // Private inheritance means:
    // Public inherited members become private (so m_public is treated as private)
    // Protected inherited members become private (so m_protected is treated as private)
    // Private inherited members stay inaccessible (so m_private is inaccessible)
public:
    Pri()
    {
        m_public = 1; // okay: m_public is now private in Pri
//        m_private = 2; // not okay: derived classes can't access private members in the base class
        m_protected = 3; // okay: m_protected is now private in Pri
    }
    
    //可重写基类的方法
    /*
     Pri p;
     p.getPublic();
     p.Base3::getPublic();//可已制定调用哪个方法（需使用public继承）
     */
    
    int getPublic(){
        std::cout << "Pri的";
        
        //可以先调用基类的该方法，方便重用代码
        Base3::getPublic();
        
        return m_public;
    }
};

// Inherit from Base protectedly
class Pro: protected Base3
{
public:
    Pro(){
        m_public = 1; // okay: m_public is now protected in Pri
        //        m_private = 2; // not okay: derived classes can't access private members in the base class
        m_protected = 3; // okay: m_protected is now protected in Pri
    }
};

/*
 
 Pri p;
 p.m_public = 10; //can't access
 
 */


#endif /* inheritance_special_hpp */
